package com.cloud.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GateWayConfig {

    @Bean
    public RouteLocator customRouteLocator1(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
                        //相当于在配置文件配置id
        RouteLocator path_route_liu = routes.route("path_route_liu", f ->
                f.path("/guonei")//相当于访问localhost:9527/guonei的时候就会触发映射
                        .uri("https://news.baidu.com/guonei"))//触发映射之后将转发到这个网络路径下
                .build();
        return path_route_liu;
    }
    @Bean
    public RouteLocator customRouteLocator2(RouteLocatorBuilder routeLocatorBuilder){
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        RouteLocator path_route_guoji = routes.route("path_route_guoji",
                f -> f.path("/guoji")
                        .uri("https://news.baidu.com/guoji")

        ).build();
        return path_route_guoji;

    }

}
